#pragma once

#define co_enter(c)                     \
    switch(c)                           \
    case -1: if (c) {                   \
        goto terminate_co;              \
        terminate_co:                   \
            c = -1;                     \
            goto bail_out_co;           \
        bail_out_co:                    \
            break;                      \
    } else                              \
    case 0:
#define co_yield(n)                                 \
        for (c = (n);;)                             \
            if (c == 0) {                           \
    case (n): ;                                     \
                break;                              \
            } else                                  \
                switch (c ? 0 : 1) for (;;)         \
                case -1: if (c)                     \
                        goto terminate_co;          \
                    else                            \
                        for (;;)                    \
                case 1:     if (c)                  \
                                goto bail_out_co;   \
                            else                    \
                case 0:
